package top.huhuiyu.teachproject.schedule;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.huhuiyu.teachproject.dao.UtilsDAO;
import top.huhuiyu.teachproject.service.AutoDataService;
import top.huhuiyu.teachproject.service.RedisService;

@EnableScheduling
@Component
@RequiredArgsConstructor
@Slf4j
public class AutoTasks {
  private final UtilsDAO utilsDAO;
  private final RedisService redisService;
  private final AutoDataService autoDataService;

  @Scheduled(initialDelay = 5 * 1000, fixedDelay = 5 * 60 * 1000)
  public void time() {
    log.debug("定时任务执行中...");
    log.debug("数据库时间：{}", utilsDAO.queryNowTimestamp());
    log.debug("redis信息：{}", redisService.get("appinfo", String.class));
  }


  @Scheduled(initialDelay = 60 * 1000, fixedDelay = 5 * 60 * 1000)
  public void users() {
    log.debug("自动创建用户...");
    log.debug("用户数量：{}", autoDataService.makeUser());
  }
}
